<html>
<body>
	{{template "header.html"}}
	{{$recipe := .recipe}} 
	<div class="recipe-left">
		<h3>Recipe</h3>
		<form action="{{if $recipe.Id}}updateRecipe{{else}}addRecipe{{end}}" method="POST" enctype="multipart/form-data">
			{{if .recipe.Id}}
				<input type="hidden" name="id" value="{{$recipe.Id}}" /> 
				<label for="id">Id:</label> 
				<input type="text" name="showid" disabled value="{{$recipe.Id}}" /><br/>
			{{end}}
			<label for="name">Name:</label>
			<input type="text" name="name" value="{{.recipe.Name}}" /><br />

			<label for="categoryId">Category:</label>			
			<select name="categoryId">
			<option></option>
			{{range .categories}}
			<option value="{{.Id}}" {{if eq .Id $recipe.CategoryId}}selected{{end}}>{{.Name}}</option>
			{{end}}
			</select><br/>
			
			<label for="code">Code:</label>
			<input type="text" name="code" value="{{.recipe.Code}}" /><br />
			
			<label for="description">Description:</label>
			<textarea name="description">{{bytesToString .recipe.Description}}</textarea><br/>
			
			<label for="display">Display:</label>
			<input type="checkbox" name="display" {{with .recipe.Display}}checked{{end}}/><br /> 
			
			<label for="image">Image:</label> 
			{{with .recipe.Image}}<img src="/file?key={{.}}" width="200px" /><br />{{end}}
			<input type="file" name="image"><br />

			<label for="thumb">Thumb:</label>
			{{with .recipe.Thumb}}<img src="/file?key={{.}}" width="200px" /><br />{{end}}
			<input type="file" name="thumb"><br />
			
			<input type="submit" value="Save" />
			<input type="submit" name="saveAndContinue" value="Save and continue editing" /> 
			{{if .recipe.Id}}<a class="del" href="deleteRecipe?id={{$recipe.Id}}">x</a>{{end}}
		</form>
	</div>
	<div class="recipe-right">
		<h3>Ingredients</h3>
		{{with .ingredients}} {{range .}}
		<div>
			{{.Name}} [{{.Count}} {{unitName .Unit}}]<a class="del"
				href="deleteIngredient?id={{.Id}}&recipeId={{$recipe.Id}}">x</a>
		</div>
		{{end}} <br /> {{end}} Add ingredient:
		<form action="addIngredient" method="POST">
			<input type="hidden" name="recipeId" value="{{.recipe.Id}}" /> <label
				for="product">Product:</label> <select name="product">
				<option /> {{range .products}}
				<option value="{{.Id}}:{{.Name}}">{{.Name}}</option> {{end}}
			</select> <select name="unit"> {{range .units}}
				<option value="{{.}}">{{unitName .}}</option> {{end}}
			</select> <input class="short-in" type="text" name="count" /> <input
				type="submit" value="Save" />
		</form>
		<h3>Add Product</h3>
		<form action="addProduct" method="POST">
			<input type="hidden" name="recipeId" value="{{$recipe.Id}}" /> 
			<label for="name">Name:</label>
			<input type="text" name="name"/>
			<input type="submit" value="Save"/>
		</form>
	</div>
	<div class="clear"></div>
	<div>
		<h3>Comments</h3>
		{{with .comments}} 
			{{range .}}
			<div>
				{{.Author}} [{{formatTime .DateCreated}}]: {{.Text}} 
				<a class="del" href="deleteRecipeComment?id={{.Id}}&recipeId={{$recipe.Id}}">x</a>
			</div>
			{{end}} <br /> 
		{{end}} 
		Add comment:
		<form action="addRecipeComment" method="POST">
			<input type="hidden" name="recipeId" value="{{.recipe.Id}}" />
			<label for="author">Author</label>
			<input type="text" name="author"/><br/>
			<textarea name="text"></textarea><br/>
			<input type="submit" value="Save" />
		</form>
	</div>

</body>
</html>